# 无限分类
def infinite2(da):
    li = []
    dic = {}
    for item in da:
        dic[item["id"]] = item
    for i in da:
        if not i["pid"]:
            li.append(dic[i["id"]])
        else:
            if i['pid'] in dic:
                if "children" not in dic[i["pid"]]:
                    dic[i["pid"]]["children"] = []
                dic[i["pid"]]["children"].append(dic[i["id"]])
            else:
                li.append(dic[i["id"]])

            # for k in dic[i["pid"]]["maindata"]:
            #     k["money"] = 0
            #     for k1 in dic[i["id"]]["maindata"]:
            #         if k1["money"]:
            #             k["money"] += k1["money"]

    totalnum = 0
    totalmoney = 0

    def checkall(aimlist):
        for k in range(len(aimlist["maindata"])):
            aimlist["totalnum"] = 0
            aimlist["totalmoney"] = 0
            aimlist["maindata"][k]["money"] = 0
            aimlist["maindata"][k]["num"] = 0

            for kk in aimlist["children"]:
                if "children" in kk:
                    checkall(kk)

                if "totalnum" in kk:
                    aimlist["totalnum"] += kk["totalnum"]
                if "totalmoney" in kk:
                    aimlist["totalmoney"] += kk["totalmoney"]

                if "money" in kk["maindata"][k]:
                    if kk["maindata"][k]["money"]:
                        aimlist["maindata"][k]["money"] += kk["maindata"][k]["money"]

                if "num" in kk["maindata"][k]:
                    if kk["maindata"][k]["num"]:
                        aimlist["maindata"][k]["num"] += kk["maindata"][k]["num"]







    for i in li:
        if "children" in i:
            checkall(i)

                # for k in range(len(dic[i["pid"]]["maindata"])):
            #     if dic[i["id"]]["maindata"][k]["money"]:
            #         dic[i["pid"]]["maindata"][k]["money"] += dic[i["id"]]["maindata"][k]["money"]

            # for k in range(len(dic[i["pid"]]["maindata"])):
            #     dic[i["pid"]]["maindata"][k]["money"] = 0
            #
            # for k in range(len(dic[i["pid"]]["maindata"])):
            #     if dic[i["id"]]["maindata"][k]["money"]:
            #         dic[i["pid"]]["maindata"][k]["money"] += dic[i["id"]]["maindata"][k]["money"]

    # for k in da:
    #     print(k["children"])

    return li

